-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aio: add h1 title to floating table of contents #16959
aio: add h1 title to floating table of contents #16959
Conversation
|
||
Observable.combineLatest(this.tocService.activeItemIndex, this.items.changes.startWith(this.items)) | ||
// We use the `asap` scheduler because updates to `activeItemIndex` are triggered by DOM changes, | ||
// which are, in turn, triggered rendering that happened due to a ChangeDetection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
English !!
a6c01b3
to
a4fecef
Compare
I rebased, fixed the conflict, and broke up the big commit into smaller ones to make the refactoring more easy to follow. |
a4fecef
to
c496a15
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nit-picks. Nothing blocking.
Loved the refactorings ❤️
// We use the `asap` scheduler because updates to `activeItemIndex` are triggered by DOM changes, | ||
// which, in turn, are caused by the rendering that happened due to a ChangeDetection. | ||
// Without asap, we would be updating the model while still in a ChangeDetection handler, which is disallowed by Angular. | ||
Observable.combineLatest(this.tocService.activeItemIndex.subscribeOn(asap), this.items.changes.startWith(this.items)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
import 'rxjs/add/operator/takeUntil'; | ||
|
||
import { ScrollService } from 'app/shared/scroll.service'; | ||
import { TocItem, TocService } from 'app/shared/toc.service'; | ||
|
||
type TocType = 'None' |'Floating' |'EmbeddedSimple' |'EmbeddedExpandable'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No whitespace after |
? 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱
<div *ngIf="hasToc" [class.collapsed]="isCollapsed"> | ||
<button *ngIf="!isEmbedded" type="button" class="toc-heading" | ||
(click)="toTop()" title="Top of page">Contents</button> | ||
<div *ngIf="type != 'None'" class="toc-inner" [class.collapsed]="isCollapsed"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOC, why !=
vs !==
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
'EmbeddedExpandable' : | ||
'EmbeddedSimple' : | ||
'Floating' : | ||
'None'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ternary operator hell 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah! It's a pyramid of beauty!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be clear: I like it 😃
@@ -67,7 +56,8 @@ aio-toc > div { | |||
} | |||
|
|||
button.toc-heading, | |||
div.toc-heading { | |||
div.toc-heading, | |||
ul.toc-list li.h1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need the element specifiers at all. Why not just .toc-heading, .toc-list .h1 { ... }
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is probably correct. I was just sort of following the convention there already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I think that Stef will change some of this anyway
aio/src/styles/2-modules/_toc.scss
Outdated
@@ -134,7 +124,7 @@ aio-toc > div { | |||
transition: all 0.3 ease-in-out; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not directly related to this PR, but I noticed this value is invalid and causes the style to be ignored. It should be 0.3s
(the s
is currently missing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll sneak that in.
display: block; | ||
height: 1px; | ||
width: 40%; | ||
margin: 24px 0px 10px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
24px
feels too much. margin: 10px 0
looks better imo 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is due to change in Stef's PR.
tocList[i].isSecondary = true; | ||
} | ||
} | ||
const count = this.tocList.reduce((c, item) => item.level !== 'h1' ? c + 1 : c, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this.tocList.filter(item => item.level !== 'h1').length
is slightly more readable 😳
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but slower and uses more memory :-P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, I know 😞 But Igor said to opt for readability over performance 😛
<a [href]="toc.href" [innerHTML]="toc.content"></a> | ||
</li> | ||
<ng-container *ngFor="let toc of tocList; let i = index"> | ||
<li #tocItem title="{{toc.title}}" *ngIf="type == 'Floating' || toc.level != 'h1'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to avoid this ngIf
, by separating the h1 element from the rest (in the component).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that but it just moves the complexity somewhere else.
Not displaying the h1
IMO is a visual choice, hence the responsibility of the template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The decision about dislaying it or not will still be in the template. But the template won't have to "extract" it from the tocList
(which sounds rather "business-logic-y").
I don't feel at all strognly about it, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that then you would need complexity in both the component class (to extract the h1) and then in the template (where it would need to duplicate the li
element for the h1).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¯\_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually also it become even more complex when you then try to get the activeIndex
to line up. This way, it just works :-)
fixture.detectChanges(); | ||
expect(tocComponentDe.queryAllNodes(By.css('li')).length).toBe(3); | ||
}); | ||
|
||
it('should only display H2 and H3 TocItems', () => { | ||
tocService.tocList.next([tocItem('Heading A', 'h1'), tocItem('Heading B'), tocItem('Heading C')]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No test for H3 😟
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱
@gkalpak Pushed a bunch of fixes from your feedback, some of which will be squashed. PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still LGTM
|
||
<button *ngIf="hasSecondary" type="button" class="toc-heading embedded secondary" | ||
(click)="toggle(false)" | ||
<button *ngIf="type == 'EmbeddedExpandable'" type="button" (click)="toggle(false)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's one more here 😛
import 'rxjs/add/operator/takeUntil'; | ||
|
||
import { ScrollService } from 'app/shared/scroll.service'; | ||
import { TocItem, TocService } from 'app/shared/toc.service'; | ||
|
||
type TocType = 'None' |'Floating' |'EmbeddedSimple' | 'EmbeddedExpandable'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are more missing whitespaces here.
@@ -92,3 +92,7 @@ export class TocComponent implements OnInit, AfterViewInit, OnDestroy { | |||
this.scrollService.scrollToTop(); | |||
} | |||
} | |||
|
|||
function count<T>(array: T[], fn: (T) => boolean) { | |||
return array.reduce((count, item) => fn(item) ? count + 1 : count, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return array.filter(fn).length
is more readable 😛
This makes the styling less fragile to changes in the HTML
We use the `asap` scheduler because updates to `activeItemIndex` are triggered by DOM changes, which, in turn, are caused by the rendering that happened due to a ChangeDetection. Without asap, we would be updating the model while still in a ChangeDetection handler, which is disallowed by Angular.
4bb3bc7
to
c9f93b9
Compare
There seems to have been a bad rebase of angular#16228 on top of angular#16959, which affected ToC styles from both PRs. This commit restores the horizontal line under `.h1` elements and the vertical blue bar on the left-hand side of the ToC (with the circle running along the bar to indicate the active section). Fixes angular#17098
There seems to have been a bad rebase of angular#16228 on top of angular#16959, which affected ToC styles from both PRs. This commit restores the horizontal line under `.h1` elements and the vertical blue bar on the left-hand side of the ToC (with the circle running along the bar to indicate the active section). Fixes angular#17098
There seems to have been a bad rebase of angular#16228 on top of angular#16959, which affected ToC styles from both PRs. This commit restores the horizontal line under `.h1` elements and the vertical blue bar on the left-hand side of the ToC (with the circle running along the bar to indicate the active section). Fixes angular#17098
There seems to have been a bad rebase of angular#16228 on top of angular#16959, which affected ToC styles from both PRs. This commit restores the horizontal line under `.h1` elements and the vertical blue bar on the left-hand side of the ToC (with the circle running along the bar to indicate the active section). Fixes angular#17098
There seems to have been a bad rebase of #16228 on top of #16959, which affected ToC styles from both PRs. This commit restores the horizontal line under `.h1` elements and the vertical blue bar on the left-hand side of the ToC (with the circle running along the bar to indicate the active section). Fixes #17098
* refactor(aio): use explicit CSS class for TOC container This makes the styling less fragile to changes in the HTML * fix(aio): schedule TocComponent.activeIndex updates via AsapScheduler We use the `asap` scheduler because updates to `activeItemIndex` are triggered by DOM changes, which, in turn, are caused by the rendering that happened due to a ChangeDetection. Without asap, we would be updating the model while still in a ChangeDetection handler, which is disallowed by Angular. * refactor(aio): do not instantiate floating ToC if not displayed * feat(aio): display the h1 at the top of the floating TOC Closes angular#16900 * refactor(aio): combine the TOC booleans flags into a "type" state * refactor(aio): remove unnecessary `hostElement` property * fix(aio): ensure that transition works on TOC * fix(aio): use strict equality in ToC template
There seems to have been a bad rebase of angular#16228 on top of angular#16959, which affected ToC styles from both PRs. This commit restores the horizontal line under `.h1` elements and the vertical blue bar on the left-hand side of the ToC (with the circle running along the bar to indicate the active section). Fixes angular#17098
* refactor(aio): use explicit CSS class for TOC container This makes the styling less fragile to changes in the HTML * fix(aio): schedule TocComponent.activeIndex updates via AsapScheduler We use the `asap` scheduler because updates to `activeItemIndex` are triggered by DOM changes, which, in turn, are caused by the rendering that happened due to a ChangeDetection. Without asap, we would be updating the model while still in a ChangeDetection handler, which is disallowed by Angular. * refactor(aio): do not instantiate floating ToC if not displayed * feat(aio): display the h1 at the top of the floating TOC Closes angular#16900 * refactor(aio): combine the TOC booleans flags into a "type" state * refactor(aio): remove unnecessary `hostElement` property * fix(aio): ensure that transition works on TOC * fix(aio): use strict equality in ToC template
There seems to have been a bad rebase of angular#16228 on top of angular#16959, which affected ToC styles from both PRs. This commit restores the horizontal line under `.h1` elements and the vertical blue bar on the left-hand side of the ToC (with the circle running along the bar to indicate the active section). Fixes angular#17098
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Closes #16900